﻿using System;
using System.Collections.Generic;
using System.Text;
using DTO;
using System.Data;
using System.Data.SqlClient;

namespace DAO
{
//    create table QUYDINH
//(
//ThoiGianBayMin int,
//ThoiGianDungMax int,
//ThoiGianDungMin int,
//SoSBTrungGianMax int,
//ThoiGianDatVe int

    public class QuyDinh_DAO
    {
        public static bool thayDoiQuyDinh(QuyDinh_DTO quyDinh)
        {
            string query = "update QUYDINH SET thoigianbaymin = " + quyDinh.thoiGianBayMin + ", thoigiandungmax = " + quyDinh.thoiGianDungMax + ", thoigiandungmin = " + quyDinh.thoiGianDungMin + ", "
                + "sosbtrunggianmax = " + quyDinh.soSBTrungGianMax + ", thoigiandatve = " + quyDinh.thoiGianDatVe + "";
            
            if(SqlDataAccessHelper.ExecuteNoneQuery(query) == 1)
            return true;
            return false;
        }

        public static QuyDinh_DTO layQuyDinh()
        {
            string query = " select * from QUYDINH ";

            DataTable dt = SqlDataAccessHelper.ExecuteQuery(query);

            QuyDinh_DTO quydinh = new QuyDinh_DTO();
            foreach (DataRow dr in dt.Rows)
            {
                quydinh.thoiGianBayMin = int.Parse(dr["ThoiGianBayMin"].ToString());
                quydinh.thoiGianDungMax = int.Parse(dr["ThoiGianDungMax"].ToString());
                quydinh.thoiGianDungMin = int.Parse(dr["ThoiGianDungMin"].ToString());
                quydinh.soSBTrungGianMax = int.Parse(dr["SoSBTrungGianMax"].ToString());
                quydinh.thoiGianDatVe = int.Parse(dr["ThoiGianDatVe"].ToString());
            }
            return quydinh;
        }
    }
}
